package org.study.module.ranger;

import java.util.ArrayList;
import java.util.List;

public class RangerShell {


    /**
     * 修改admin中的install.properties
     */
    public static List<String> admin(){
        List<String> commands = new ArrayList<>();
        commands.add("# 数据库配置");
        commands.add("db_root_user=root                # MySQL root用户名");
        commands.add("db_root_password=Root@123        # MySQL root密码");
        commands.add("db_name=ranger                   # 数据库名");
        commands.add("db_user=rangeradmin              # 数据库用户");
        commands.add("db_password=Ranger@123           # 数据库用户密码");
        commands.add("db_host=mysql-host               # MySQL主机名/IP");
        commands.add("db_port=3306                     # MySQL端口");
        commands.add("# Ranger Admin配置");
        commands.add("ranger_admin_host=ranger-admin-node  # Ranger Admin节点主机名");
        commands.add("ranger_admin_port=6080               # Web界面端口");
        commands.add("ranger_admin_username=admin          # 管理员用户名");
        commands.add("ranger_admin_password=Admin@123      # 管理员密码（登录Web界面用）");
        commands.add("# Kerberos集成（关键，与Hadoop Kerberos一致）");
        commands.add("ranger_admin_kerberos_enabled=true   # 启用Kerberos");
        commands.add("ranger_admin_principal=ranger/admin@EXAMPLE.COM  # Ranger Admin的Kerberos主体");
        commands.add("ranger_admin_keytab=/etc/security/keytabs/ranger-admin.keytab  # 对应的keytab路径");
        commands.add("java_home=$JAVA_HOME  # JAVA_HOME路径");
        commands.add("安装并启动");
        commands.add("./setup.sh");
        commands.add("./ews/ranger-admin-services.sh start");
        return commands;
    }

    public static List<String> userSync(){
        List<String> commands = new ArrayList<>();
        commands.add("#第一步解压");
        commands.add("# 关联Ranger Admin");
        commands.add("ranger_usersync_ranger_admin_url=http://ranger-admin-node:6080");
        commands.add("ranger_usersync_username=admin");
        commands.add("ranger_usersync_password=Admin@123");
        commands.add("# 用户同步源（以Unix本地用户为例）");
        commands.add("ranger_usersync_source=unix                # 同步源：unix/ldap");
        commands.add("ranger_usersync_unix_sync_interval=60       # 同步间隔（秒）");
        commands.add("ranger_usersync_keytab=/etc/security/keytabs/ranger-usersync.keytab  # 若启用Kerberos");
        commands.add("ranger_usersync_principal=ranger/usersync@EXAMPLE.COM");
        commands.add("java_home=$JAVA_HOME");
        commands.add("安装并启动");
        commands.add("./setup.sh");
        commands.add("./usersync/services.sh start");
        return commands;
    }

    public static List<String> hdfsPlugin(){
        List<String> commands = new ArrayList<>();
        commands.add("#第一步解压");
        commands.add("# HDFS配置路径");
        commands.add("HADOOP_HOME=$HADOOP_HOME");
        commands.add("hadoop_conf=$HADOOP_HOME/etc/hadoop");
        commands.add("# Ranger Admin地址");
        commands.add("POLICY_MGR_URL=http://ranger-admin-node:6080");
        commands.add("# Kerberos集成");
        commands.add("ranger.plugin.hdfs.kerberos.enabled=true");
        commands.add("ranger.plugin.hdfs.service.name=hdfs  # 与Ranger Admin中创建的服务名一致");
        commands.add("ranger.plugin.hdfs.keytab=/etc/security/keytabs/hdfs.keytab  # HDFS的keytab");
        commands.add("ranger.plugin.hdfs.principal=hdfs/_HOST@EXAMPLE.COM  # HDFS的Kerberos主体");
        commands.add("#安装插件");
        commands.add("./enable-hdfs-plugin.sh");
        commands.add("重启 HDFS 服务");
        commands.add("stop-dfs.sh");
        commands.add("start-dfs.sh");
        return commands;
    }

    public static List<String> yarnPlugin(){
        List<String> commands = new ArrayList<>();
        commands.add("#第一步解压");
        commands.add("# HDFS配置路径");
        commands.add("HADOOP_HOME=$HADOOP_HOME");
        commands.add("hadoop_conf=$HADOOP_HOME/etc/hadoop");
        commands.add("# Ranger Admin地址");
        commands.add("POLICY_MGR_URL=http://ranger-admin-node:6080");
        commands.add("# Kerberos集成");
        commands.add("ranger.plugin.yarn.kerberos.enabled=true");
        commands.add("ranger.plugin.yarn.service.name=yarn  # 与Ranger Admin中创建的服务名一致");
        commands.add("ranger.plugin.yarn.keytab=/etc/security/keytabs/yarn.keytab  # YARN的keytab");
        commands.add("ranger.plugin.yarn.principal=yarn/_HOST@EXAMPLE.COM  # YARN的Kerberos主体");
        commands.add("#安装插件");
        commands.add("./enable-yarn-plugin.sh");
        commands.add("重启 YARN 服务");
        commands.add("stop-yarn.sh");
        commands.add("start-yarn.sh");
        return commands;
    }

}
